package com.ganzalang.gmall.designpatterns.proxy;

import lombok.extern.slf4j.Slf4j;

/**
 * @description: 代理模式
 * @author: ganzalang
 */
@Slf4j
public class ProxyPatternDemo {

    /**
     * demo只演示了静态代理，代理类在功能上其实是对原对象的增强
     * @param args
     */
    public static void main(String[] args) {
        SubjectProxy subjectProxy = new SubjectProxy(new SubjectImpl());
        subjectProxy.request();
    }

    public interface Subject {
        void request();
    }

    public static class SubjectImpl implements Subject {

        @Override
        public void request() {
            log.info("执行方法");
        }
    }

    public static class SubjectProxy implements Subject {

        private Subject subject;

        public SubjectProxy(Subject subject) {
            this.subject = subject;
        }

        @Override
        public void request() {
            log.info("执行代理的前置逻辑");
            subject.request();
            log.info("执行代理的后置逻辑");
        }
    }
}
